home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / Mesa-1.2.1 / src-tk / window.c < prev   
Encoding:
C/C++ Source or Header  |  1995-07-05  |  16.9 KB  |  526 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "tk.h"
  5. #include "private.h"
  6.  
  7. /******************************************************************************/
  8.  
  9. Display *xDisplay = 0;
  10. int xScreen = 0; 
  11. Window wRoot = 0;
  12. Atom deleteWindowAtom;
  13. WINDOW_REC w = {
  14.     0, 0, 300, 300, TK_RGB|TK_SINGLE|TK_DIRECT
  15. };
  16. float colorMaps[] = {
  17.     0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 1.000000, 
  18.     0.000000, 1.000000, 0.333333, 0.776471, 0.443137, 0.556863, 
  19.     0.443137, 0.556863, 0.219608, 0.666667, 0.666667, 0.333333, 
  20.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  21.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  22.     0.666667, 0.333333, 0.039216, 0.078431, 0.117647, 0.156863, 
  23.     0.200000, 0.239216, 0.278431, 0.317647, 0.356863, 0.400000, 
  24.     0.439216, 0.478431, 0.517647, 0.556863, 0.600000, 0.639216, 
  25.     0.678431, 0.717647, 0.756863, 0.800000, 0.839216, 0.878431, 
  26.     0.917647, 0.956863, 0.000000, 0.000000, 0.000000, 0.000000, 
  27.     0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059, 
  28.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  29.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  30.     0.498039, 0.498039, 0.749020, 0.749020, 0.749020, 0.749020, 
  31.     0.749020, 0.749020, 0.749020, 0.749020, 1.000000, 1.000000, 
  32.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  33.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  34.     0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059, 
  35.     0.247059, 0.247059, 0.247059, 0.247059, 0.498039, 0.498039, 
  36.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  37.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  38.     0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000, 
  39.     1.000000, 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 
  40.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  41.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  42.     0.247059, 0.247059, 0.498039, 0.498039, 0.498039, 0.498039, 
  43.     0.498039, 0.498039, 0.498039, 0.498039, 0.749020, 0.749020, 
  44.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  45.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  46.     1.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  47.     0.000000, 0.000000, 0.000000, 0.000000, 0.247059, 0.247059, 
  48.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  49.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  50.     0.498039, 0.498039, 0.749020, 0.749020, 0.749020, 0.749020, 
  51.     0.749020, 0.749020, 0.749020, 0.749020, 1.000000, 1.000000, 
  52.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  53.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  54.     0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059, 
  55.     0.247059, 0.247059, 0.247059, 0.247059, 0.498039, 0.498039, 
  56.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  57.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  58.     0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000, 
  59.     1.000000, 1.000000, 1.000000, 1.000000, 0.000000, 0.000000, 
  60.     1.000000, 1.000000, 0.000000, 0.000000, 1.000000, 1.000000, 
  61.     0.333333, 0.443137, 0.776471, 0.556863, 0.443137, 0.219608, 
  62.     0.556863, 0.666667, 0.666667, 0.333333, 0.666667, 0.333333, 
  63.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  64.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  65.     0.039216, 0.078431, 0.117647, 0.156863, 0.200000, 0.239216, 
  66.     0.278431, 0.317647, 0.356863, 0.400000, 0.439216, 0.478431, 
  67.     0.517647, 0.556863, 0.600000, 0.639216, 0.678431, 0.717647, 
  68.     0.756863, 0.800000, 0.839216, 0.878431, 0.917647, 0.956863, 
  69.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  70.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  71.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  72.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  73.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  74.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  75.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  76.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  77.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  78.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  79.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  80.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  81.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  82.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  83.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  84.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  85.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  86.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  87.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  88.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  89.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  90.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  91.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  92.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  93.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  94.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  95.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  96.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  97.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  98.     0.854902, 1.000000, 0.000000, 0.141176, 0.282353, 0.427451, 
  99.     0.568627, 0.713726, 0.854902, 1.000000, 0.000000, 0.141176, 
  100.     0.282353, 0.427451, 0.568627, 0.713726, 0.854902, 1.000000, 
  101.     0.000000, 0.141176, 0.282353, 0.427451, 0.568627, 0.713726, 
  102.     0.854902, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  103.     1.000000, 1.000000, 1.000000, 1.000000, 0.333333, 0.443137, 
  104.     0.443137, 0.219608, 0.776471, 0.556863, 0.556863, 0.666667, 
  105.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  106.     0.666667, 0.333333, 0.666667, 0.333333, 0.666667, 0.333333, 
  107.     0.666667, 0.333333, 0.666667, 0.333333, 0.039216, 0.078431, 
  108.     0.117647, 0.156863, 0.200000, 0.239216, 0.278431, 0.317647, 
  109.     0.356863, 0.400000, 0.439216, 0.478431, 0.517647, 0.556863, 
  110.     0.600000, 0.639216, 0.678431, 0.717647, 0.756863, 0.800000, 
  111.     0.839216, 0.878431, 0.917647, 0.956863, 0.000000, 0.000000, 
  112.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  113.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  114.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  115.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  116.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  117.     0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 
  118.     0.000000, 0.000000, 0.247059, 0.247059, 0.247059, 0.247059, 
  119.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  120.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  121.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  122.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  123.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  124.     0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 0.247059, 
  125.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  126.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  127.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  128.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  129.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  130.     0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 0.498039, 
  131.     0.498039, 0.498039, 0.498039, 0.498039, 0.749020, 0.749020, 
  132.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  133.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  134.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  135.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  136.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  137.     0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 0.749020, 
  138.     0.749020, 0.749020, 1.000000, 1.000000, 1.000000, 1.000000, 
  139.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  140.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  141.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  142.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  143.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  144.     1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 
  145. };
  146. float tkRGBMap[8][3] = {
  147.     {
  148.     0, 0, 0
  149.     },
  150.     {
  151.     1, 0, 0
  152.     },
  153.     {
  154.     0, 1, 0
  155.     },
  156.     {
  157.     1, 1, 0
  158.     },
  159.     {
  160.     0, 0, 1
  161.     },
  162.     {
  163.     1, 0, 1
  164.     },
  165.     {
  166.     0, 1, 1
  167.     },
  168.     {
  169.     1, 1, 1
  170.     }
  171. };
  172.  
  173. /******************************************************************************/
  174.  
  175. void tkCloseWindow(void)
  176. {
  177.  
  178.     if (xDisplay) {
  179.     cursorNum = 0;
  180.  
  181.     ExposeFunc = 0;
  182.     ReshapeFunc = 0;
  183.     IdleFunc = 0;
  184.     DisplayFunc = 0;
  185.     KeyDownFunc = 0;
  186.     MouseDownFunc = 0;
  187.     MouseUpFunc = 0;
  188.     MouseMoveFunc = 0;
  189.  
  190.     glFlush();
  191.     glFinish();
  192.     if (TK_HAS_OVERLAY(w.type)) {
  193.         XDestroyWindow(xDisplay, w.wOverlay);
  194.         glXDestroyContext(xDisplay, w.cOverlay);
  195.         XFreeColormap(xDisplay, w.cMapOverlay);
  196.         XFree((char *)w.vInfoOverlay);
  197.     }
  198.     XDestroyWindow(xDisplay, w.wMain);
  199.     glXDestroyContext(xDisplay, w.cMain);
  200.     XFreeColormap(xDisplay, w.cMapMain);
  201.     XFree((char *)w.vInfoMain);
  202.     XCloseDisplay(xDisplay);
  203.     xDisplay = 0;
  204.     }
  205. }
  206.  
  207. /******************************************************************************/
  208.  
  209. void tkInitDisplayMode(GLenum type)
  210. {
  211.  
  212.     w.type = type;
  213. }
  214.  
  215. /******************************************************************************/
  216.  
  217. void tkInitPosition(int x, int y, int width, int height)
  218. {
  219.  
  220.     w.x = x;
  221.     w.y = y;
  222.     w.w = width;
  223.     w.h = height;
  224. }
  225.  
  226. /******************************************************************************/
  227.  
  228. static int ErrorHandler(Display *xDisplay, XErrorEvent *event)
  229. {
  230.     char buf[80];
  231.  
  232.     printf("\nReceived X error!\n");
  233.     printf("\tError code   : %d\n", event->error_code);
  234.     printf("\tRequest code : %d\n", event->request_code);
  235.     printf("\tMinor code   : %d\n\n", event->minor_code);
  236.     XGetErrorText(xDisplay, event->error_code, buf, 80);
  237.     printf("\tError text : '%s'\n\n", buf);
  238.     return 0;
  239. }
  240.  
  241. static XVisualInfo *FindMainVisual(GLenum type)
  242. {
  243.     int list[32], i;
  244.  
  245.     i = 0;
  246.  
  247.     list[i++] = GLX_LEVEL;
  248.     list[i++] = 0;
  249.  
  250.     if (TK_IS_DOUBLE(type)) {
  251.     list[i++] = GLX_DOUBLEBUFFER;
  252.     }
  253.  
  254.     if (TK_IS_RGB(type)) {
  255.     list[i++] = GLX_RGBA;
  256.     list[i++] = GLX_RED_SIZE;
  257.     list[i++] = 1;
  258.     list[i++] = GLX_GREEN_SIZE;
  259.     list[i++] = 1;
  260.     list[i++] = GLX_BLUE_SIZE;
  261.     list[i++] = 1;
  262.     if (TK_HAS_ALPHA(type)) {
  263.         list[i++] = GLX_ALPHA_SIZE;
  264.         list[i++] = 1;
  265.     }
  266.     if (TK_HAS_ACCUM(type)) {
  267.         list[i++] = GLX_ACCUM_RED_SIZE;
  268.         list[i++] = 1;
  269.         list[i++] = GLX_ACCUM_GREEN_SIZE;
  270.         list[i++] = 1;
  271.         list[i++] = GLX_ACCUM_BLUE_SIZE;
  272.         list[i++] = 1;
  273.         if (TK_HAS_ALPHA(type)) {
  274.         list[i++] = GLX_ACCUM_ALPHA_SIZE;
  275.         list[i++] = 1;
  276.         }
  277.     }
  278.     } else if (TK_IS_INDEX(type)) {
  279.     list[i++] = GLX_BUFFER_SIZE;
  280.     list[i++] = 1;
  281.     }
  282.  
  283.     if (TK_HAS_DEPTH(type)) {
  284.     list[i++] = GLX_DEPTH_SIZE;
  285.     list[i++] = 1;
  286.     }
  287.  
  288.     if (TK_HAS_STENCIL(type)) {
  289.     list[i++] = GLX_STENCIL_SIZE;
  290.     list[i++] = 1;
  291.     }
  292.  
  293.     list[i] = (int)None;
  294.  
  295.     return glXChooseVisual(xDisplay, xScreen, list);
  296. }
  297.  
  298. static XVisualInfo *FindOverlayVisual(void)
  299. {
  300.     int list[3];
  301.  
  302.     list[0] = GLX_LEVEL;
  303.     list[1] = 1;
  304.     list[2] = (int)None;
  305.  
  306.     return glXChooseVisual(xDisplay, xScreen, list);
  307. }
  308.  
  309. static GLenum GetMainWindowType(XVisualInfo *vi)
  310. {
  311.     GLenum mask;
  312.     int x, y, z;
  313.  
  314.     mask = 0;
  315.  
  316.     glXGetConfig(xDisplay, vi, GLX_DOUBLEBUFFER, &x);
  317.     if (x) {
  318.     mask |= TK_DOUBLE;
  319.     } else {
  320.     mask |= TK_SINGLE;
  321.     }
  322.  
  323.     glXGetConfig(xDisplay, vi, GLX_RGBA, &x);
  324.     if (x) {
  325.     mask |= TK_RGB;
  326.     glXGetConfig(xDisplay, vi, GLX_ALPHA_SIZE, &x);
  327.     if (x > 0) {
  328.         mask |= TK_ALPHA;
  329.     }
  330.     glXGetConfig(xDisplay, vi, GLX_ACCUM_RED_SIZE, &x);
  331.     glXGetConfig(xDisplay, vi, GLX_ACCUM_GREEN_SIZE, &y);
  332.     glXGetConfig(xDisplay, vi, GLX_ACCUM_BLUE_SIZE, &z);
  333.     if (x > 0 && y > 0 && z > 0) {
  334.         mask |= TK_ACCUM;
  335.     }
  336.     } else {
  337.     mask |= TK_INDEX;
  338.     }
  339.  
  340.     glXGetConfig(xDisplay, vi, GLX_DEPTH_SIZE, &x);
  341.     if (x > 0) {
  342.     mask |= TK_DEPTH;
  343.     }
  344.  
  345.     glXGetConfig(xDisplay, vi, GLX_STENCIL_SIZE, &x);
  346.     if (x > 0) {
  347.     mask |= TK_STENCIL;
  348.     }
  349.  
  350.     if (glXIsDirect(xDisplay, w.cMain)) {
  351.     mask |= TK_DIRECT;
  352.     } else {
  353.     mask |= TK_INDIRECT;
  354.     }
  355.  
  356.     return mask;
  357. }
  358.  
  359. static int WaitForMainWindow(Display *d, XEvent *e, char *arg)
  360. {
  361.  
  362.     if (e->type == MapNotify && e->xmap.window == w.wMain) {
  363.     return GL_TRUE;
  364.     } else {
  365.     return GL_FALSE;
  366.     }
  367. }
  368.  
  369. static int WaitForOverlayWindow(Display *d, XEvent *e, char *arg)
  370. {
  371.  
  372.     if (e->type == MapNotify && e->xmap.window == w.wOverlay) {
  373.     return GL_TRUE;
  374.     } else {
  375.     return GL_FALSE;
  376.     }
  377. }
  378.  
  379. GLenum tkInitWindow(char *title)
  380. {
  381.     XSetWindowAttributes wa;
  382.     XTextProperty tp;
  383.     XSizeHints sh;
  384.     XEvent e;
  385.     int erb, evb;
  386.     GLenum overlayFlag;
  387.  
  388.     if (!xDisplay) {
  389.     xDisplay = XOpenDisplay(0);
  390.     if (!xDisplay) {
  391.         fprintf(stderr, "Can't connect to xDisplay!\n");
  392.         return GL_FALSE;
  393.     }
  394.     if (!glXQueryExtension(xDisplay, &erb, &evb)) {
  395.         fprintf(stderr, "No glx extension!\n");
  396.         return GL_FALSE;
  397.     }
  398.     xScreen = DefaultScreen(xDisplay);
  399.     wRoot = RootWindow(xDisplay, xScreen);
  400.     XSetErrorHandler(ErrorHandler);
  401.     }
  402.  
  403.     if (TK_HAS_OVERLAY(w.type)) {
  404.     overlayFlag = GL_TRUE;
  405.     } else {
  406.     overlayFlag = GL_FALSE;
  407.     }
  408.     w.type &= ~TK_OVERLAY;
  409.  
  410.     w.vInfoMain = FindMainVisual(w.type);
  411.     if (!w.vInfoMain) {
  412.     fprintf(stderr, "Window type not found!\n");
  413.     return GL_FALSE;
  414.     }
  415.  
  416.     w.cMain = glXCreateContext(xDisplay, w.vInfoMain, None,
  417.                    (TK_IS_DIRECT(w.type))?GL_TRUE:GL_FALSE);
  418.     if (!w.cMain) {
  419.     fprintf(stderr, "Can't create a context!\n");
  420.     return GL_FALSE;
  421.     }
  422.  
  423.     w.type = GetMainWindowType(w.vInfoMain);
  424.  
  425.     if (TK_IS_INDEX(w.type)) {
  426.         /* Color Indexed windows needs a writable colormap */
  427.     if (w.vInfoMain->class != StaticColor &&
  428.         w.vInfoMain->class != StaticGray) {
  429.         w.cMapMain = XCreateColormap(xDisplay, wRoot, w.vInfoMain->visual,
  430.                          AllocAll);
  431.     } else {
  432.         w.cMapMain = XCreateColormap(xDisplay, wRoot, w.vInfoMain->visual,
  433.                          AllocNone);
  434.     }
  435.     } else {
  436.         /* RGB colormap is AllocNone, share the root colormap if possible */
  437.     Screen *scr = DefaultScreenOfDisplay(xDisplay);
  438.     int scrnum = DefaultScreen(xDisplay);
  439.     if (MaxCmapsOfScreen(scr)==1
  440.         && w.vInfoMain->visual==DefaultVisual(xDisplay,scrnum)) {
  441.         w.cMapMain = DefaultColormap(xDisplay,scrnum);
  442.     }
  443.     else {
  444.         w.cMapMain = XCreateColormap(xDisplay, wRoot, w.vInfoMain->visual,
  445.                      AllocNone);
  446.     }
  447.     }
  448.     if (TK_IS_INDEX(w.type) || w.vInfoMain->class==DirectColor) {
  449.        tkSetRGBMap(256, colorMaps);
  450.     }
  451.     wa.colormap = w.cMapMain;
  452.     wa.background_pixmap = None;
  453.     wa.border_pixel = 0;
  454.     wa.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask |
  455.             ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
  456.     w.wMain = XCreateWindow(xDisplay, wRoot, w.x, w.y, w.w, w.h, 0,
  457.                 w.vInfoMain->depth, InputOutput,
  458.                 w.vInfoMain->visual,
  459.                 CWBackPixmap|CWBorderPixel|CWEventMask|CWColormap,
  460.                 &wa);
  461.  
  462.     XInstallColormap( xDisplay, w.cMapMain );
  463.  
  464.     XStringListToTextProperty(&title, 1, &tp);
  465.     sh.flags = USPosition | USSize;
  466.     XSetWMProperties(xDisplay, w.wMain, &tp, &tp, 0, 0, &sh, 0, 0);
  467.     deleteWindowAtom = XInternAtom(xDisplay, "WM_DELETE_WINDOW", False);
  468.     XSetWMProtocols(xDisplay, w.wMain, &deleteWindowAtom, 1);
  469.     XMapWindow(xDisplay, w.wMain);
  470.     drawAllowFlag = GL_FALSE;
  471.     XIfEvent(xDisplay, &e, WaitForMainWindow, 0);
  472.  
  473.     if (overlayFlag == GL_TRUE) {
  474.     w.vInfoOverlay = FindOverlayVisual();
  475.     if (w.vInfoOverlay) {
  476.         w.cOverlay = glXCreateContext(xDisplay, w.vInfoOverlay, None,
  477.                       GL_TRUE);
  478.         w.cMapOverlay = XCreateColormap(xDisplay, wRoot,
  479.                         w.vInfoOverlay->visual, AllocNone);
  480.         tkSetOverlayMap(256, colorMaps);
  481.         wa.colormap = w.cMapOverlay;
  482.         wa.background_pixmap = None;
  483.         wa.border_pixel = 0;
  484.         w.wOverlay = XCreateWindow(xDisplay, w.wMain, 0, 0, w.w, w.h, 0,
  485.                        w.vInfoOverlay->depth, InputOutput,
  486.                        w.vInfoOverlay->visual,
  487.                        CWBackPixmap|CWBorderPixel|CWColormap,
  488.                        &wa);
  489.         XMapWindow(xDisplay, w.wOverlay);
  490.         XSetWMColormapWindows(xDisplay, w.wMain, &w.wOverlay, 1);
  491.         w.type |= TK_OVERLAY;
  492.     } else {
  493.         fprintf(stderr, "Can't create a overlay plane!\n");
  494.     }
  495.     }
  496.  
  497.     if (!glXMakeCurrent(xDisplay, w.wMain, w.cMain)) {
  498.     fprintf(stderr, "Can't make window current drawable!\n");
  499.     return GL_FALSE;
  500.     }
  501.     XFlush(xDisplay);
  502.  
  503.     return GL_TRUE;
  504. }
  505.  
  506. /******************************************************************************/
  507.  
  508. void tkQuit(void)
  509. {
  510.  
  511.     tkCloseWindow();
  512.     exit(0);
  513. }
  514.  
  515. /******************************************************************************/
  516.  
  517. void tkSwapBuffers(void)
  518. {
  519.  
  520.     if (xDisplay) {
  521.     glXSwapBuffers(xDisplay, w.wMain);
  522.     }
  523. }
  524.  
  525. /******************************************************************************/
  526.